@page "/Configurations/LiveFansMedalTaskConfig"
@using Microsoft.AspNetCore.Authorization
@using Ray.BiliBiliTool.Config.Options;
@attribute [Authorize]
@rendermode InteractiveServer
@inherits BaseConfigComponent<LiveFansMedalTaskOptions>

<PageTitle>直播粉丝牌任务配置</PageTitle>

<MudContainer>
    <MudText Typo="Typo.h4" Class="mb-4">直播粉丝牌任务配置</MudText>

    @if (_isLoading)
    {
        <MudProgressCircular Color="Color.Primary" Indeterminate="true" />
    }
    else
    {
        <EditForm Model="@_config" OnValidSubmit="HandleValidSubmitAsync">
            <DataAnnotationsValidator />

            <!-- 基础配置卡片 -->
            <MudCard Class="mb-4">
                <MudCardHeader>
                    <CardHeaderContent>
                        <MudText Typo="Typo.h6">基础配置</MudText>
                    </CardHeaderContent>
                </MudCardHeader>
                <MudCardContent>
                    <MudGrid>
                        <MudItem xs="12" md="6">
                            <MudSwitch T="bool" @bind-Value="_config.IsEnable"
                                Label="启用任务" Color="Color.Primary" />
                        </MudItem>
                        <MudItem xs="12" md="6">
                            <MudTextField T="string" @bind-Value="_config.Cron" Label="定时任务Cron表达式"
                                HelperText="例如：0 5 0 * * ? (每天凌晨0点5分执行)"
                                Disabled="!_config.IsEnable" />
                        </MudItem>
                    </MudGrid>
                </MudCardContent>
            </MudCard>

            <!-- 详细配置卡片 -->
            @if (_config.IsEnable)
            {
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">详细配置</MudText>
                        </CardHeaderContent>
                    </MudCardHeader>
                    <MudCardContent>
                        <MudGrid>
                            <MudItem xs="12" md="6">
                                <MudTextField T="string" @bind-Value="_config.DanmakuContent" Label="自定义发送弹幕内容"
                                    HelperText="如 '打卡' 等来触发直播间内机器人关键词" />

                                <MudNumericField T="int" @bind-Value="_config.HeartBeatNumber" Label="心跳包发送的个数/挂机的时间(分钟)"
                                    Min="1" Class="mt-3" />

                                <MudNumericField T="int" @bind-Value="_config.HeartBeatSendGiveUpThreshold" Label="心跳包发送连续失败多少次时放弃"
                                    Min="1" Class="mt-3" />

                                <MudSwitch T="bool" @bind-Value="_config.IsSkipLevel20Medal"
                                    Label="是否跳过粉丝牌等级 >= 20 的" Color="Color.Primary" Class="mt-3" />
                            </MudItem>

                            <MudItem xs="12" md="6">
                                <MudNumericField T="int" @bind-Value="_config.LikeNumber" Label="点赞次数"
                                    Min="0" HelperText="默认值为30（用于点亮粉丝勋章）" />

                                <MudNumericField T="int" @bind-Value="_config.SendDanmakuNumber" Label="发送弹幕次数"
                                    Min="0" Class="mt-3" />

                                <MudNumericField T="int" @bind-Value="_config.SendDanmakugiveUpThreshold" Label="弹幕发送失败多少次时放弃"
                                    Min="1" Class="mt-3" />
                            </MudItem>
                        </MudGrid>
                    </MudCardContent>
                </MudCard>
            }

            <!-- 操作按钮 -->
            <MudCard Class="mt-4">
                <MudCardActions>
                    <MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">保存配置</MudButton>
                    <MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="LoadConfigAsync" Class="ml-2">重新加载</MudButton>
                </MudCardActions>
            </MudCard>
        </EditForm>

        @if (_saveMessage.HasValue)
        {
            <MudAlert Severity="@(_saveSuccess ? Severity.Success : Severity.Error)" Class="mt-3">
                @_saveMessage
            </MudAlert>
        }
    }
</MudContainer>

<MudThemeProvider/>
<MudPopoverProvider/>
<MudDialogProvider/>
<MudSnackbarProvider/>
